var echartsTheme = 'macarons';
//var echartsTheme = 'shine';
var legendTextColor = "#0B61A4";
$(function(){
    srjbgcGo();
    lineGo4();
    barGo2();
    barGo5();
    ysjcGo();

});

function srjbgcGo(){
    $('#div_pie1').html("");
    var myChart = echarts.init(document.getElementById('div_pie1'), echartsTheme);
    var option = {
      /*  title: {
            text: '退税按类型分布',
        },*/
        tooltip : {
            trigger: 'item',
            formatter: "{b} : {c} 万元"
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            y: 'bottom',
            data:[]
        },
        series: [
            {
                //name:'模型数量',
                type: 'pie',
                radius: ['45%', '70%'],
                center:['30%','60%'],
                avoidLabelOverlap: true,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: "{b}, {d}%"
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '20',
                            fontWeight: 'bold'
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: []
            }
        ]
    };
    myChart.setOption(option);


    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/querySrjbgc",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var jg=d.data.srjbgc;
                $('#v_zsrlj').html(jg.zsrlj);
                $('#v_sslj').html(jg.sslj);
                $('#v_ssby').html(jg.ssby);
                $('#v_sblj').html(jg.sblj);
                $('#v_sbby').html(jg.sbby);
                $('#v_qtlj').html(jg.qtlj);
                $('#v_qtby').html(jg.qtby);

                var datas=d.data.echartsList;

                var lengData=[];

                for(var d in datas){
                    lengData.push(datas[d].name);
                }
                //隐藏loading动画
                myChart.hideLoading();
                myChart.setOption({
                    legend: {
                        data:lengData
                    },
                    series: [{
                        data:datas
                    }]
                });

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });
}



function barGo2(){
    $('#div_bar2').html("");
    var myChart = echarts.init(document.getElementById('div_bar2'), echartsTheme);
    var option = {
        title : {
           /* text: '某地区蒸发量和降水量',
            subtext: '纯属虚构'*/
        },
        tooltip : {
            trigger: 'axis'
        },
        legend: {
            data:['本期','同期']
        },
    /*    toolbox: {
            show : true,
            feature : {
                dataView : {show: true, readOnly: false},
                magicType : {show: true, type: ['line', 'bar']},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },*/
        calculable : true,
        xAxis : [
            {
                type : 'category',
                data : []
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        dataZoom:{
            show:true,
            satrt:1,
            end:50,
            showDetail: false,
            zoomLock:true,
            handleSize: 0
        },
        series : [
            {
                name:'本期',
                type:'bar',
                //data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
                data:[],
                markPoint : {
                    data : [
                        {type : 'max', name: '最大值'},
                        {type : 'min', name: '最小值'}
                    ]
                },
                markLine : {
                    data : [
                        {type : 'average', name: '平均值'}
                    ]
                }
            },
            {
                name:'同期',
                type:'bar',
                //data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
                data:[],
                markPoint : {
                    data : [
                      /*  {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
                        {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}*/
                        {type : 'max', name: '年最高'},
                        {type : 'min', name: '年最低'}
                    ]
                },
                markLine : {
                    data : [
                        {type : 'average', name : '平均值'}
                    ]
                }
            }
        ]
    };
    myChart.setOption(option);

    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/querySrzjqk",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                var datas=d.data;
                $('#v_ljzf').html( Math.round(datas.ljzf*10000)/100+'%');
                $('#v_pjzf').html(Math.round(datas.pjzf*10000)/100+'%');
                //$('#v_pjzf').html(datas.pjzf*100+'%');
                //隐藏loading动画
               myChart.hideLoading();
                   myChart.setOption({
                       xAxis: [
                           {
                               data: d.data.xAxisData
                           }
                       ],
                      series: [{
                          data: d.data.bq
                      },{
                          data: d.data.tq
                      }]
                  });

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });
}


function lineGo4(){
    $('#div_bar4').html("");
    var myChart = echarts.init(document.getElementById('div_bar4'), echartsTheme);
    //app.title = '坐标轴刻度与标签对齐';

   var option = {
        title: {
           /* text: '未来一周气温变化',
            subtext: '纯属虚构'*/
        },
        tooltip: {
            trigger: 'axis'
        },
       dataZoom:{
           show:true,
           satrt:1,
           end:50,
           showDetail: false,
           handleSize: 0
       },
        legend: {
            data:['清欠率','新欠率']
        },
       /* toolbox: {
            show: true,
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar']},
                restore: {},
                saveAsImage: {}
            }
        },*/
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            //data: ['一月','二月','三月','四月','五月','六月']
            data: [],
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name:'清欠率',
                type:'line',
                //data:[11, 11, 15, 13, 12, 13, 10],
                data:[],
                label: { //图形上的文本标签，可用于说明图形的一些数据信息，比如值，名称等
                    normal: {
                        //正常情况
                        formatter: '{c}%'
                    }
                },
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'}
                    ]
                }
            },
            {
                name:'新欠率',
                type:'line',
                //data:[1, -2, 2, 5, 3, 2, 0],
                data:[],
                markPoint: {
                    data: [
                        {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
                    ]
                },
                markLine: {
                    data: [
                        {type: 'average', name: '平均值'},
                        [{
                            symbol: 'none',
                            x: '90%',
                            yAxis: 'max'
                        }, {
                            symbol: 'circle',
                            label: {
                                normal: {
                                    position: 'start',
                                    formatter: '最大值'
                                }
                            },
                            type: 'max',
                            name: '最高点'
                        }]
                    ]
                }
            }
        ]
    };

    myChart.setOption(option);


    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryQsztqk",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {
            layer.close(lay);
            if (d.code == '200') {
                $('#v_qcqs').html(d.data.qcqs);
                $('#v_xqsk').html(d.data.xqsk);
                $('#v_qlqs').html(d.data.qlqs);
                $('#v_qmqs').html(d.data.qmqs);

                var datas=d.data;
                //隐藏loading动画
                myChart.hideLoading();
                myChart.setOption({
                    xAxis: [
                        {
                            data: d.data.xAxisData
                        }
                    ],
                    series: [{
                        data: d.data.qq
                    },{
                        data: d.data.xq
                    }]
                });

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }


    });
}


function barGo5(){

    $('#div_bar5').html("");
    var myChart = echarts.init(document.getElementById('div_bar5'), echartsTheme);
    $('#div_bar6').html("");
    var myChart6 = echarts.init(document.getElementById('div_bar6'), echartsTheme);
    var  option = {
        title: [
            {
                //text: '正负条形图',
                left: 'center',
                top: 20,
                textStyle: {
                    color: 'blue',
                    fontSize: '10',
                },
            },
            {
                //text: '实验室',
                //borderColor: '#999',
                //borderWidth: 1,
                textStyle: {
                    fontSize: 10
                },
                left: 'center',
                top: '88%'
            },
        ],
        tooltip: {
            trigger: 'axis',//坐标轴触发，主要在柱状图，折线图等会使用类目轴的图表中使用。
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow' |'cross'
            }
        },
        legend: {
            //data: ['利润', '支出', '收入'],
            //bottom: '0',
        },
        grid: {
            left: '0',
            right: '5%',
            containLabel: true
        },
        dataZoom:{
                showDetail: false,
                zoomLock: false,
                start: 0,
                end: 70,
                handleSize: 0
            },
        xAxis: [{
            //type: 'category',
            axisTick: { //坐标轴刻度相关设置。
                show: true,
            },
            axisLabel:{
                //inside:true,
              interval:0,
                rotate:45,   //标签倾斜显示
                formatter:function(val){
                    var strs=val.split('');
                    var str='';
                    for(var i=0,s;s=strs[i++];){
                        str +=s;
                        if(!(i%4)){
                            str += '\n';
                        }
                    }
                    return str;
                }

            },

            data: [],

        }],
        yAxis: [{
            type: 'value',
            //name: 'Z值',
            nameLocation: 'center',
            nameGap: 40
        }],
        series: [
            {
                //name: '企业资产收益率',
                type: 'bar',
                barWidth: '30%',
                label: { //图形上的文本标签，可用于说明图形的一些数据信息，比如值，名称等
                    normal: { //正常情况
                        show: true, //是否显示标签
                        position: 'inside', //标签的位置。
                        distance: 5, //距离图形元素的距离。当 position 为字符描述值（如 'top'、'insideRight'）时候有效。default: 5
                        rotate: 0, //标签旋转。从 -90 度到 90 度。正值是逆时针。
                        formatter: '{c}%'
                    }
                },   axisLabel:{
                    //inside:true,
                    interval:0
                },
            /* data: [  20,15,8,5,-10,-15,20,15,8,5,-10,-15,20,15,8,5
               /* lue: 20, label: labelRight},
                {value: 15, label: labelRight},
                8, 5,
                {value: -10, label: labelRight},
                -15
                ]*/
                data: [],
            }
        ]
    };

    myChart.setOption(option);
    myChart6.setOption(option);

    var lay1 = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryFhyzssrbh",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {

            layer.close(lay1);
            if (d.code == '200') {
                var datas=d.data;
                //隐藏loading动画
                myChart.hideLoading();
                myChart.setOption({
                    xAxis: [
                        {
                            data: d.data.xAxisData
                        }
                    ],
                    series: [{
                        data: d.data.bhl
                    }]
                });

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay1);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });

    var lay6 = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryFszzssrbh",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {

            layer.close(lay6);
            if (d.code == '200') {
                var datas=d.data;
                //隐藏loading动画
                myChart6.hideLoading();
                myChart6.setOption({
                    xAxis: [
                        {
                            data: d.data.xAxisData
                        }
                    ],
                    series: [{
                        data: d.data.bhl
                    }]
                });

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay6);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });

}

function ysjcGo(){

    var lay = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/queryYsjcfb",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {

            layer.close(lay);
            if (d.code == '200') {
                $("#table1").bootstrapTable({
                    columns: [[{
                        title: '预算级次', field: 'ysjc', width: "50px", align: 'center', valign: 'middle'
                    }, {
                        title: '收入（亿元）',
                        field: 'sr',
                        width: "50px",
                        align: 'center',
                        valign: 'middle',
                        formatter: function (v) {
                            return v;
                        }
                    }, {
                        title: '占比%',
                        field: 'zb',
                        width: "50px",
                        align: 'center',
                        valign: 'middle',
                        formatter: function (v) {
                            return v;
                        }
                    }
                    ]],
                    data: d.rows
                });
            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });

}